//
//  CompleteOrderClassificationVC.m
//  SeaMelonSeeds_Counselor
//
//  Created by 尤振宇 on 2017/8/3.
//  Copyright © 2017年 杨笑. All rights reserved.
//

#import "CompleteOrderClassificationVC.h"
#import "FaceToFaceCompleteCell.h"
#import "CompleteOrderTableViewCell.h"
#import "Order.h"
#import "OrderDetailsViewController.h"
#import "OrderListApi.h"

@interface CompleteOrderClassificationVC ()
@property(nonatomic,assign)OrderType orderType;

@end

@implementation CompleteOrderClassificationVC

- (instancetype)initWithType:(OrderType)type
{
    self = [super init];
    if (self) {
        self.orderType = type;
        self.listApi = [[OrderListApi alloc]initWithType:type completed:YES];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    if (self.orderType == mianduimian_OrderType) {
//        self.view.backgroundColor = [UIColor whiteColor];
//        [self.tableView registerCellWithNib:@"FaceToFaceCompleteCell"];
//    }else{
        [self.tableView registerCellWithNib:@"CompleteOrderTableViewCell"];
//    }
    [self configNotDataView:[UIImage imageNamed:@"noOrder"] text:@"暂无订单"];
    [self addMj_footer];
    [self addMj_header];
    [self loadData];
    self.tableView.bounces = YES;
    // Do any additional setup after loading the view.
}

-(void)loadData
{
    WeakSelf(self)
    [self.listApi startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        
        if (kCode(request.responseJSONObject)) {
            if (weakself.listApi.page == 1) {
                [weakself.dataArray removeAllObjects];
            }
            NSArray *arr = [[request.responseJSONObject objectForKey:@"data"] objectForKey:@"list"];
            for (NSDictionary *dic in arr) {
                Order *order = [Order new];
                [order setValuesForKeysWithDictionary:dic];
                [weakself.dataArray addObject:order];
            }
        }
        [self showOrHideDataView];
        [weakself.tableView reloadData];
        [weakself endRefreshing];
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        [weakself endRefreshing];
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WeakSelf(self)
    Order *order = self.dataArray[indexPath.row];
//    if (self.orderType == mianduimian_OrderType) {
//        FaceToFaceCompleteCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FaceToFaceCompleteCell" forIndexPath:indexPath];
//        
//        cell.fillResults = ^(id obj) {
//            
//        };
//        
//        [cell setOrder:order];
//        
//        return cell;
//    }else{
        CompleteOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CompleteOrderTableViewCell" forIndexPath:indexPath];
        [cell setOrder:order type:self.orderType];
        
        
        cell.touchCheckDetails = ^(id obj) {
            [weakself pushViewController:[OrderDetailsViewController OrderDetailsViewController:order] animated:YES];
        };
        
        cell.describe.spreadText = ^(id obj) {
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:(UITableViewRowAnimationAutomatic)];
        };
        return cell;
//    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Order *order = self.dataArray[indexPath.row];
//    if (self.orderType == mianduimian_OrderType) {
//        return 95;
//    }else{
        return [order cellHeight] + 155;
//    }
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 20;
}
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
